package olive.mycourse.servlets;

import java.io.IOException;
import java.sql.ResultSet;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.swing.JOptionPane;
//This code is write by Samir 0830300017

public class Control extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	// pages
	private static String LOGINPAGE = "loginPage.jsp";

	public Control() {
		super();
		// TODO Auto-generated constructor stub
	}


	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String pageTo = "", pageFrom="";
		String state = "NEWPAGE";
		String[] path=null;
		Map parameters = request.getParameterMap();
		pageFrom = request.getHeader("REFERER");
		path=pageFrom.split("/");
		pageFrom=path[path.length-1];
		Boolean t = null;
		//if(pageFrom.equalsIgnoreCase(LOGINPAGE)){
			
			/* if(!type.equalsIgnoreCase("")){
			 ResultSet result=work.getResult();
			 request.getSession().setAttribute("loginUser", result);//Save user information to Session
			 pageTo=type;//more to be add
			 request.setAttribute("message", "Login Success");
			 }else{
				 pageTo=pageFrom;
				 request.setAttribute("message", "Login Fail");
			 }*/
		//}
		   
			   RequestDispatcher view = request.getRequestDispatcher("/log.jsp");
			view.forward(request, response);}
		   
	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doGet(request, response);
	}
}
